<template>
  <router-view></router-view>
</template>

<script setup lang="ts">
import actions from "./actions";
import hooks, { useLanguage } from "@/hooks";
const { isArabic, isCn, isEn } = useLanguage()
import { Local, Session } from "@/utils/storage";
const { proxy } = getCurrentInstance() as any;
import { CommonEnum } from "./utils/common/enums/commonEnum";
import { getLanguageList } from "./utils/common/common";
import { getToken } from "./utils/auth";
const dev = import.meta.env.VITE_DEV
//初始化多语言数据
!Local.get(CommonEnum.setRedisLocalLanguage) && getLanguageList(true, true)
proxy.$i18n.locale =
  Local.get("localLanguage") || Local.set("localLanguage", "en-US");
isArabic.value
  ? document.documentElement.setAttribute("dir", "rtl")
  : isCn.value
    ? document.documentElement.setAttribute("dir", "ltr")
    : document.documentElement.setAttribute("dir", "ltr");

watch(
  isArabic,
  (v) => {
    hooks.menuHook.showEmployeeSecondMenu = false
    if (v) {
      document.documentElement.setAttribute("dir", "rtl");
    } else {
      document.documentElement.setAttribute("dir", "ltr");
    }
  },
  { deep: true }
);
watch(
  () => proxy.$i18n.locale,
  (newVal) => {
    hooks.menuHook.showEmployeeSecondMenu = false
    if (newVal === "arabic") {
      document.documentElement.setAttribute("dir", "rtl");
    } else {
      document.documentElement.setAttribute("dir", "ltr");
    }
  },
  {
    deep: true,
  }
);
onBeforeMount(() => {
  getToken() && Session.get('userInfo') && getLanguageList(true, false);
})
onUnmounted(() => {
  window.removeEventListener('load', () => { }, false);
  window.axiosCancel = []
  // 添加取消标记
  config.cancelToken = new axios.CancelToken(cancel => {
    window.axiosCancel.push(cancel)
  });
  
})
</script>

<style lang="scss">
@import "./styles/default.scss";
</style>
